import processing.core.PApplet;
import processing.core.PConstants;


public class Controls {
	private PApplet parent = null;
	@SuppressWarnings("unused")
	private Tooltip tooltip = null;
	
	
	// CONSTANTS
	final public static int STOP = 0;
	final public static int REWIND = 1;
	final public static int PLAYPAUSE = 2;
	final public static int FASTFORWARD = 3;
	final public static int EJECT = 4;
	
	
	final private static int BGSTROKE = 233;
	final private static int BGFILL = 255;
	final private static int STOPSTROKE = 150;
	final private static int STOPFILL = 150;
	final private static int STOPHOVER = 1;
	final private static int REWINDSTROKE = 150;
	final private static int REWINDFILL = 150;
	final private static int REWINDHOVER = 1;
	final private static int PLAYPAUSESTROKE = 150;
	final private static int PLAYPAUSEFILL = 150;
	final private static int PLAYPAUSEHOVER = 1;
	final private static int FASTFORWARDSTROKE = 150;
	final private static int FASTFORWARDFILL = 150;
	final private static int FASTFORWARDHOVER = 1;
	final private static int EJECTSTROKE = 150;
	final private static int EJECTFILL = 150;
	final private static int EJECTHOVER = 1;
	
	// BG Rect Coordinates
	final private static int BGX1 = 0;
	final private static int BGY1 = 0;
	final private static int BGX2 = 104;
	final private static int BGY2 = 20;

	// Stop Rect Coordinates
	final private static int STOPX1 = 3;
	final private static int STOPY1 = 2;
	final private static int STOPX2 = 19;
	final private static int STOPY2 = 18;
	
	// Rewind  Triangle Coordinates
	final private static int REWINDX1 = 22; // LEFT MIDDLE
	final private static int REWINDY1 = 10;
	final private static int REWINDX2 = 30; // TOP RIGHT
	final private static int REWINDY2 = 2;
	final private static int REWINDX3 = 30; // BOTTOM RIGHT
	final private static int REWINDY3 = 18;
	final private static int REWINDSPACING = 8;

	// Play Triangle Coordinates
	final private static int PLAYX1 = 44; // TOP LEFT
	final private static int PLAYY1 = 2;
	final private static int PLAYX2 = 44; // BOTTOM RIGHT
	final private static int PLAYY2 = 18;
	final private static int PLAYX3 = 60; // RIGHT MIDDLE
	final private static int PLAYY3 = 10;

	// Pause Rect Coordinates
	final private static int PAUSEX1 = 46;
	final private static int PAUSEY1 = 2;
	final private static int PAUSEX2 = 49;
	final private static int PAUSEY2 = 18;
	final private static int PAUSESPACING = 6;

	// Fast Forward Triangle Coordinates
	final private static int FASTFORWARDX1 = 64; // TOP LEFT
	final private static int FASTFORWARDY1 = 2;
	final private static int FASTFORWARDX2 = 64; // BOTTOM LEFT
	final private static int FASTFORWARDY2 = 18;
	final private static int FASTFORWARDX3 = 72; // RIGHT MIDDLE
	final private static int FASTFORWARDY3 = 10;
	final private static int FASTFORWARDSPACING = 8;

	// Eject Triangle Coordinates
	final private static int EJECTX1 = 84; // BOTTOM LEFT
	final private static int EJECTY1 = 14;
	final private static int EJECTX2 = 100; // BOTTOM RIGHT
	final private static int EJECTY2 = 14;
	final private static int EJECTX3 = 92; // TOP MIDDLE
	final private static int EJECTY3 = 2;
	// Eject Rect Coordinates
	final private static int EJECTY4 = 16;
	final private static int EJECTY5 = 18;

	public Controls(PApplet p, Tooltip t) {
		this.parent = p;
		this.tooltip = t;
	}

	public void display() {
		parent.rectMode(PConstants.CORNERS);

		parent.stroke(BGSTROKE);
		parent.fill(BGFILL);
		parent.rect(BGX1, BGY1, BGX2, BGY2);
		
		parent.stroke(STOPSTROKE);
		if(parent.mouseX >= STOPX1 && parent.mouseX <= STOPX2 && parent.mouseY >= STOPY1 && parent.mouseY <= STOPY2)
			parent.fill(STOPHOVER);
		else
			parent.fill(STOPFILL);
		parent.rect(STOPX1, STOPY1, STOPX2, STOPY2);
		
		parent.stroke(REWINDSTROKE);
		if(parent.mouseX >= REWINDX1 && parent.mouseX <= (REWINDX2+REWINDSPACING) && parent.mouseY >= REWINDY2 && parent.mouseY <= REWINDY3)
			parent.fill(REWINDHOVER);
		else
			parent.fill(REWINDFILL);
		parent.triangle(REWINDX1, REWINDY1, REWINDX2, REWINDY2, REWINDX3, REWINDY3);
		parent.triangle(REWINDX1+REWINDSPACING, REWINDY1, REWINDX2+REWINDSPACING, REWINDY2, REWINDX3+REWINDSPACING, REWINDY3);

		parent.stroke(PLAYPAUSESTROKE);
		if(parent.mouseX >= PLAYX1 && parent.mouseX <= PLAYX3 && parent.mouseY >= PLAYY1 && parent.mouseY <= PLAYY2)
			parent.fill(PLAYPAUSEHOVER);
		else
			parent.fill(PLAYPAUSEFILL);

		if(((IssuePlayer)parent).ipState == ((IssuePlayer)parent).PAUSE)
			parent.triangle(PLAYX1, PLAYY1, PLAYX2, PLAYY2, PLAYX3, PLAYY3);
		else {
			parent.rect(PAUSEX1, PAUSEY1, PAUSEX2, PAUSEY2);
			parent.rect(PAUSEX1+PAUSESPACING, PAUSEY1, PAUSEX2+PAUSESPACING, PAUSEY2);
		}

		parent.stroke(FASTFORWARDSTROKE);
		if(parent.mouseX >= FASTFORWARDX1 && parent.mouseX <= (FASTFORWARDX3+FASTFORWARDSPACING) && parent.mouseY >= FASTFORWARDY1 && parent.mouseY <= FASTFORWARDY2)
			parent.fill(FASTFORWARDHOVER);
		else
			parent.fill(FASTFORWARDFILL);
		parent.triangle(FASTFORWARDX1, FASTFORWARDY1, FASTFORWARDX2, FASTFORWARDY2, FASTFORWARDX3, FASTFORWARDY3);
		parent.triangle(FASTFORWARDX1+FASTFORWARDSPACING, FASTFORWARDY1, FASTFORWARDX2+FASTFORWARDSPACING, FASTFORWARDY2, FASTFORWARDX3+FASTFORWARDSPACING, FASTFORWARDY3);


		parent.stroke(EJECTSTROKE);
		if(parent.mouseX >= EJECTX1 && parent.mouseX <= EJECTX2 && parent.mouseY >= EJECTY3 && parent.mouseY <= EJECTY5)
			parent.fill(EJECTHOVER);
		else
			parent.fill(EJECTFILL);
		parent.triangle(EJECTX1, EJECTY1, EJECTX2, EJECTY2, EJECTX3, EJECTY3);
		parent.rect(EJECTX1, EJECTY4, EJECTX2, EJECTY5);
	}
	
	public int isClicked() {
		if(parent.mouseX >= STOPX1 && parent.mouseX <= STOPX2 && parent.mouseY >= STOPY1 && parent.mouseY <= STOPY2)
			return 0;

		if(parent.mouseX >= REWINDX1 && parent.mouseX <= (REWINDX2+REWINDSPACING) && parent.mouseY >= REWINDY2 && parent.mouseY <= REWINDY3)
			return 1;

		if(parent.mouseX >= PLAYX1 && parent.mouseX <= PLAYX3 && parent.mouseY >= PLAYY1 && parent.mouseY <= PLAYY2)
			return 2;

		if(parent.mouseX >= FASTFORWARDX1 && parent.mouseX <= (FASTFORWARDX3+FASTFORWARDSPACING) && parent.mouseY >= FASTFORWARDY1 && parent.mouseY <= FASTFORWARDY2)
			return 3;

		if(parent.mouseX >= EJECTX1 && parent.mouseX <= EJECTX2 && parent.mouseY >= EJECTY3 && parent.mouseY <= EJECTY5)
			return 4;

		return -1;
	}
}
